package com.example.rabbitmq.config;

import com.example.rabbitmq.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQQuorumConfig {
    //创建交换机
    @Bean("quorumExchange")
    public Exchange quorumExchange() {
        return ExchangeBuilder.topicExchange(Constants.QUORUM_EXCHANGE).durable(true).build();
    }
    //创建交换机
    @Bean("quorumQueue")
    public Queue quorumQueue() {
        return QueueBuilder.durable(Constants.QUORUM_QUEUE).quorum().build();
    }
    //创建绑定
    @Bean("quorumBinding")
    public Binding quorumBinding(@Qualifier("quorumQueue") Queue queue, @Qualifier("quorumExchange") Exchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).with("quorum").noargs();
    }
}


